package com.qsmx.qingqiuticket.app.delegate.back.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.qsmx.qingqiuticket.app.R;
import com.qsmx.qingqiuticket.app.delegate.back.holder.VersionHolder;
import com.qsmx.qingqiuticket.app.entity.VersionEntity;

import java.util.List;

public class VersionAdapter extends RecyclerView.Adapter<VersionHolder> {

    private Context mContext;
    private List<VersionEntity.BodyBean> mData;

    public VersionAdapter(Context mContext) {
        this.mContext = mContext;
    }

    public void setData(List<VersionEntity.BodyBean> data) {
        this.mData = data;
    }

    //定义接口
    public static interface OnItemClickListener {
        void onItemClick(View view, int position);
    }

    //声明自定义的监听接口
    private OnItemClickListener monItemClickListener = null;

    //提供set方法
    public void setonItemClickListener(OnItemClickListener listener) {
        this.monItemClickListener = listener;
    }

    @NonNull
    @Override
    public VersionHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new VersionHolder(LayoutInflater.from(mContext).inflate(R.layout.adapter_version_info, parent, false));
    }

    @SuppressLint({"RecyclerView", "SetTextI18n"})
    @Override
    public void onBindViewHolder(@NonNull VersionHolder holder, int position) {

        holder.tvVersionNum.setText("V" + mData.get(position).getVersion());
        holder.tvVersionDesc.setText(mData.get(position).getUpgradeInfo());
        holder.tvTime.setText(mData.get(position).getReleaseTime());
        holder.tvInstall.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                monItemClickListener.onItemClick(view, position);
            }
        });
    }

    @Override
    public int getItemCount() {
        if (mData != null && !mData.isEmpty()) {
            return mData.size();
        } else {
            return 0;
        }
    }
}
